/*
Copyright (c) [2019年5月1日] [吴超]
[MBT_studio] is licensed under Mulan PSL v2.
You can use this software according to the terms and conditions of the Mulan PSL v2.
You may obtain a copy of Mulan PSL v2 at:
		 http://license.coscl.org.cn/MulanPSL2
THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
See the Mulan PSL v2 for more details.
*/
#pragma once



#ifdef BasicDataAPI_EXPORTS
#define BDataAPI_EXPORT __declspec(dllexport)
#else
#define BDataAPI_EXPORT __declspec(dllimport)
#endif


#include <基本类型.h>
#include <basic_vec.h>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <unordered_map>


struct S_Scene;


struct S_板载缓存;
struct S_Mesh;
struct S_纹理;
struct S_纹理采样器;

//struct S_引擎配置;

//struct S_Props;
//struct S_Prop枚举项;
//struct S_MapPtrItem;
//struct S_摄像机;
//struct S_GPU计算;
//struct S_字体;
//struct S_Object;
//struct S_Physics;
//
//class C_节点基类;
//class C_节点树;
//class C_Key分配器;
//class C_StrKey分配器;



//既能绑定单个纹理也能绑定纹理集
typedef struct EngineAPI_EXPORT {
	void**	m_纹理信息;	//VK的纹理信息  不是其它自定义数据结构
	uint32* m_绑定位置;
	uint32* m_绑定数量;

	uint16	m_槽数量;
}S_GPU纹理参数槽;




struct S_全局缓存 {

	S_板载缓存* g_顶层加速结构构建缓存;
	S_板载缓存* m_场景物体网格属性;
	S_板载缓存* m_几何属性;
	S_板载缓存* m_2D线;
	S_板载缓存* g_字符纹理UV;
	S_板载缓存* g_字符;
	S_板载缓存* g_凸包图元;
	S_板载缓存* g_凸包图元区域;
	S_板载缓存* g_波形属性;

	

	S_板载缓存* g_材质;
	S_GPU内存块 m_材质;
	S_板载缓存* g_光追物体实例属性ID;
	S_板载缓存* m_全局绑定参数指针;

	S_板载缓存* m_平行光缓冲区;
	S_板载缓存* m_点光源缓冲区;
	S_板载缓存* m_区域光缓冲区;
	S_板载缓存* m_聚光灯缓冲区;

	S_板载缓存* m_灯光索引;
	S_板载缓存* g_灯光投影矩阵;


	S_板载缓存* g_光追物体属性ID;


	S_板载缓存* m_I32动态属性;
	S_板载缓存* m_UI32动态属性;
	S_板载缓存* g_UI64缓存;
	S_板载缓存* m_F32动态属性;
	S_板载缓存* m_Vec2动态属性;
	S_板载缓存* m_Vec3动态属性;
	S_板载缓存* m_Vec4动态属性;

	S_板载缓存* m_iVec2动态属性;
	S_板载缓存* m_iVec3动态属性;
	S_板载缓存* m_iVec4动态属性;

	S_板载缓存* m_uVec2动态属性;
	S_板载缓存* m_uVec3动态属性;
	S_板载缓存* m_uVec4动态属性;
	S_板载缓存* m_Mat44动态属性;
	S_板载缓存* m_U_Mat44;
	S_板载缓存* g_采样曲线属性;
	S_板载缓存* g_纹理属性;

	S_板载缓存* g_实例材质ID;


	S_板载缓存* g_MPM_坐标;
	S_板载缓存* g_PHY_前一帧坐标;
	S_板载缓存* g_PHY_速度和年龄;
	S_板载缓存* g_MPM_密度_lambda;
	S_板载缓存* g_MPM_速度梯度;
	S_板载缓存* g_MPM_网格速度;
	S_板载缓存* g_MPM_网格密度;
	S_板载缓存* g_PHY_压力;
	S_板载缓存* m_Delta;
	S_板载缓存* g_PHY_粒子类型和状态;


	S_板载缓存* g_PHY_排序键值;
	S_板载缓存* g_PHY_排序临时键值;
	S_板载缓存* g_PHY_排序键值偏移A;
	S_板载缓存* g_PHY_排序键值偏移B;
	S_板载缓存* g_PHY_排序键值数量;
	S_板载缓存* g_PHY_粒子网格索引;
	S_板载缓存* g_PHY_PBF参数;


	S_板载缓存* g_PHY_飞溅坐标;
	S_板载缓存* g_PHY_飞溅速度;
	S_板载缓存* g_PHY_飞溅粒子寿命;
	S_板载缓存* g_PHY_飞溅排序键值;
	S_板载缓存* g_PHY_飞溅粒子发射排序键值;
	S_板载缓存* g_PHY_飞溅粒子发射区间数量;

	S_板载缓存* g_PHY_物理力;

	S_GPU内存块 g_全局绑定参数;
	S_GPU内存块 g_灯光方向;


	S_板载缓存* g_粒子位置;
	S_板载缓存* g_粒子速度;
	S_板载缓存* g_粒子旋转;
	S_板载缓存* g_粒子大小;

	//=============================== 平面显示数据 =====================================
	S_板载缓存* g顶点;
	S_板载缓存* g索引;
	S_板载缓存* g间接;
	S_板载缓存* g2D层;

	S_板载缓存* g_字体顶点;
	S_板载缓存* g_字体索引;
	S_板载缓存* g_字体元素;

	S_板载缓存* g_2D多边形顶点;
	S_板载缓存* g_2D多边形索引;
	S_板载缓存* g_2D多边形元素;



	//=============================== 网格数据 =====================================
	S_板载缓存* g_自定义属性索引;
	S_板载缓存* g_顶点v;
	S_板载缓存* g_顶点vn;
	S_板载缓存* g_顶点vc;
	S_板载缓存* g_顶点vnt;
	S_板载缓存* g_索引_A;
	S_板载缓存* g_索引_B;

	S_板载缓存* g_顶点curve;
	S_板载缓存* g_顶点Aabb;
	S_板载缓存* g_颜色;
	S_板载缓存* g_UV坐标;
	S_板载缓存* g_UV索引;
	S_板载缓存* g_面;
	S_板载缓存* g_网格面属性;
	S_板载缓存* g_BLAS_0;
	S_板载缓存* g_BLAS_1;

	S_板载缓存* g_邻接面索引;
	S_板载缓存* g_面法线;
	S_板载缓存* g_面中心;

	S_板载缓存* g_文字纹理坐标;
	S_板载缓存* g_字符纹理坐标ID;
	S_板载缓存* g_GPU内存_点_uvec2;
	S_板载缓存* g_GPU内存_点_uvec3;

	//用于渲染
	S_板载缓存* g_TLAS_0;
	//用于通用计数
	S_板载缓存* g_TLAS_1;

	S_板载缓存* g_实例AS_0;
	S_板载缓存* g_实例AS_1;
	S_板载缓存* g_RtMesh;
	
	S_板载缓存* g_骨骼属性;
	S_板载缓存* g_骨骼权重;

	S_板载缓存* g_间接;
	S_板载缓存* g_索引间接;
	S_板载缓存* g_网格变换属性;

	S_板载缓存* g_I32动态属性_点;
	S_板载缓存* g_UI32动态属性_点;
	S_板载缓存* g_F32动态属性_点;
	S_板载缓存* g_Vec2动态属性_点;
	S_板载缓存* g_Vec3动态属性_点;
	S_板载缓存* g_Vec4动态属性_点;
	S_板载缓存* g_iVec2动态属性_点;
	S_板载缓存* g_iVec3动态属性_点;
	S_板载缓存* g_iVec4动态属性_点;

	S_板载缓存* g_I32动态属性_面;
	S_板载缓存* g_UI32动态属性_面;
	S_板载缓存* g_F32动态属性_面;
	S_板载缓存* g_Vec2动态属性_面;
	S_板载缓存* g_Vec3动态属性_面;
	S_板载缓存* g_Vec4动态属性_面;
	S_板载缓存* g_iVec2动态属性_面;
	S_板载缓存* g_iVec3动态属性_面;
	S_板载缓存* g_iVec4动态属性_面;

	S_GPU内存块 g_透明链表计数;
	S_板载缓存* g_透明链表纹理;
	S_纹理* g_透明链表头;



	/************************************* 材质属性 **********************************/
	S_板载缓存* g_全局纹理属性;
	


	/************************************* 灯光属性 **********************************/



	//=============================== 预设网格 =====================================

	S_Mesh* m_方形区域光物体网格;
	S_Mesh* m_圆形区域光物体网格;

	S_Mesh* g_me_包围盒网格;

	S_Mesh* g_骨头锥形;
	S_Mesh* g_骨节圆形;

	S_Mesh* g_粒子球体网格;
	S_Mesh* g_粒子方体网格;


	
	//=============================== 物体数据 =====================================
	std::vector<S_板载缓存*> g_物体颜色;

	S_GPU纹理参数槽 g_全局模型纹理槽;



	static struct S_TexArrayRes* g_默认图标;

	static S_纹理* g_空纹理;
	static S_纹理采样器* g_默认采样器;
	
	
	//==================================== 材质 ========================================

	//S_GPU内存块索引 m_网格自定义属性索引;
	static std::atomic_int32_t m_着色器引用数量;
	static S_板载缓存* g_属性索引;


};




S_全局缓存& f_buf_getGlobal();
void		f_NodeCtx_set默认场景(S_Scene* scene);
S_Scene*	f_NodeCtx_get默认场景();



struct BDataAPI_EXPORT S_缺损纹理 {
	S_纹理* g_GBuffer_顶点坐标;
	S_纹理* g_GBuffer_法线阴影;

	S_纹理* g_缺损方体纹理;


	S_纹理采样器* g_阴影采样器;
	S_纹理采样器* g_颜色纹理采样器;
	S_纹理采样器* g_平铺纹理采样器;

	S_纹理* g_缺损阴影纹理;
	S_纹理* g_缺损立方体阴影纹理;
};
S_缺损纹理& f_g_纹理(uint32 设备 = 0);


struct BDataAPI_EXPORT S_预设材质 {
	
	struct S_材质管线* g_基本光照点材质;
	struct S_材质管线* g_基本光照线材质;
	struct S_材质管线* g_基本光照线段材质;
	struct S_材质管线* g_基本光照面材质;

	struct S_材质管线* g_PBR;
	struct S_材质管线* g_PBR_Shadow;
	struct S_材质管线* g_Sky;

	struct S_材质管线* g_PBR线段材质;
	struct S_材质管线* g_线段材质;

};

S_预设材质& f_g_预设材质(uint32 设备 = 0);

